package com.isdepci.project.carbon.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.carbon.domain.BFossilFuelParameter;
import com.isdepci.project.carbon.domain.BSolidFuel;
import com.isdepci.project.carbon.domain.param.WeatherDataExcel;
import com.isdepci.project.carbon.service.IBSolidFuelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 固体燃料燃烧碳排放Controller
 *
 * @author isdepci
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/solid/fuel")
public class BSolidFuelController extends BaseController
{
    @Autowired
    private IBSolidFuelService bSolidFuelService;


    /**
     * 查询燃料名称查询对应燃料数据
     */
    @GetMapping("/getFossilFuelParameters")
    public BFossilFuelParameter getFossilFuelParameters(@RequestParam String fuelName) {
        return bSolidFuelService.getFossilFuelParameters(fuelName);
    }


    /**
     * 固体燃料计算
     */
    @GetMapping("/calSolidFuel")
    public AjaxResult calSolidFuel(@RequestParam Long projectId) {
        return bSolidFuelService.calSolidFuel(projectId);
    }



    /**
     * 查询固体燃料燃烧碳排放列表
     */
    //  @PreAuthorize("@ss.hasPermi('solid:fuel:list')")
    @GetMapping("/list")
    public TableDataInfo list(BSolidFuel bSolidFuel)
    {
        startPage();
        List<BSolidFuel> list = bSolidFuelService.selectBSolidFuelList(bSolidFuel);
        return getDataTable(list);
    }

    /**
     * 导出固体燃料燃烧碳排放列表
     */
    //  @PreAuthorize("@ss.hasPermi('solid:fuel:export')")
    @Log(title = "固体燃料燃烧碳排放", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BSolidFuel bSolidFuel)
    {
        List<BSolidFuel> list = bSolidFuelService.selectBSolidFuelList(bSolidFuel);
        ExcelUtil<BSolidFuel> util = new ExcelUtil<BSolidFuel>(BSolidFuel.class);
        return util.exportExcel(list, "fuel");
    }

    /**
     * 上传保存数据
     * @param excel
     * @return
     */
    @PostMapping("/changeData")
    public AjaxResult changeDataByProjectId(@RequestBody WeatherDataExcel excel) {
        return bSolidFuelService.changeDataByProjectId(excel);
    }


    /**
     * 获取固体燃料燃烧碳排放详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('solid:fuel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bSolidFuelService.selectBSolidFuelById(id));
    }

    /**
     * 新增固体燃料燃烧碳排放
     */
    //  @PreAuthorize("@ss.hasPermi('solid:fuel:add')")
    @Log(title = "固体燃料燃烧碳排放", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BSolidFuel bSolidFuel)
    {
        return toAjax(bSolidFuelService.insertBSolidFuel(bSolidFuel));
    }

    /**
     * 修改固体燃料燃烧碳排放
     */
    //  @PreAuthorize("@ss.hasPermi('solid:fuel:edit')")
    @Log(title = "固体燃料燃烧碳排放", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BSolidFuel bSolidFuel)
    {
        return toAjax(bSolidFuelService.updateBSolidFuel(bSolidFuel));
    }

    /**
     * 删除固体燃料燃烧碳排放
     */
    //  @PreAuthorize("@ss.hasPermi('solid:fuel:remove')")
    @Log(title = "固体燃料燃烧碳排放", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bSolidFuelService.deleteBSolidFuelByIds(ids));
    }
}
